<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        #app {
            padding: 10px;
        }

        .inp {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .inp input {
            width: 250px;
            padding-left: 10px;
            height: 30px;
            outline: none;
            border: 0;
            border-radius: 5px;
            background-color: rgb(243, 242, 242);
        }

        .inp p {
            font-size: 14px;
        }

        .jishu {
            display: flex;
            justify-content: space-between;
            color: white;
            margin-top: 10px;
        }

        .jishu .box {
            padding: 0 10px;
            font-size: 14px;
            height: 25px;
            line-height: 25px;
            background-color: rgb(43, 150, 121);
            border-radius: 5px;
        }

        .jishu .box:nth-child(3) {
            background-color: goldenrod;
        }

        .list {
            margin: 10px 0;
        }

        h4 {
            margin-bottom: 10px;
        }

        .list .task {
            margin: 10px 0;
            padding: 0 10px;
            display: flex;
            justify-content: space-between;
            background-color: goldenrod;
            height: 40px;
            line-height: 40px;
            border-radius: 10px;
            color: white;
            font-size: 14px;
        }

        .list .static {
            background-color: rgb(43, 150, 121);
        }

        .list .task .left {
            display: flex;

        }

        .list .task .left input {
            margin-right: 20px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="inp">
            <input type="text" placeholder="输入任务名称" v-model="inputText">
            <p @click="add">新增</p>
        </div>
        <div class="jishu">
            <div class="box">全部任务({{ this.list.length }})</div>
            <div class="box">已完成({{ finish }})</div>
            <div class="box">未完成({{ this.list.length - finish }})</div>
        </div>
        <div class="list">
            <h4>任务列表</h4>
            <div :class="{ task: true, static: item.status }" v-for="(item,index) in list" :key="index">

                <div class="left">
                    <input type="checkbox" @click="change(item)">
                    <div>{{item.id}}&emsp;{{ item.name }}</div>
                </div>
                <span @click="shanchu(item,index)">删除</span>
            </div>
            <div class="empty" v-show="list.length == 0">新建一个任务吧！</div>
        </div>
    </div>
</body>

</html>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.min.js"></script>
<script>
    var v = new Vue({
        el: '#app',
        data: {
            inputText: '',
            list: [
                // {id:1,name:'睡觉'}
            ]
        },
        methods: {
            add() {
                if (this.inputText) {
                    var obj = { id: this.list.length + 1, name: this.inputText, status: false }
                    this.list.push(obj)
                    // console.log(this.list);
                    this.inputText = ''
                }
            },
            change(item) {
                item.status = !item.status;
                console.log(item.status);
            },
            shanchu(item, index) {
                this.list.splice(index, 1)
            },
        },
        computed: {
            finish(){
                var num = 0
                this.list.forEach((item) => {
                    if (item.status) {
                        num++
                    }
                })
                return num
            }
        },
        watch:{
            list:{
                handler(){
                    console.log(11);
                }

            }
        }
    })

</script>